package com.taikang.system.listener;

import com.taikang.system.entity.SysUploadSet;
import com.taikang.system.service.ISysUploadSetService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.servlet.ServletContext;

/**
 * SYSTEM模块初始化操作
 *
 * @version 0.1
 * @creator taikang
 * @create-time Jun 21, 2012   4:44:43 PM
 */
@Component
public class SystemInitDataListener implements ApplicationListener<ContextRefreshedEvent> {

    private Log log = LogFactory.getLog(SystemInitDataListener.class);

    @Autowired(required = false)
    private ServletContext servletContent;

    @Resource(name = "sysUploadSetServiceImpl")
    private ISysUploadSetService sysUploadSetService;

    public void onApplicationEvent(ContextRefreshedEvent event) {
        log.info("====== SYSTEM模块数据初始化开始======");

        if (null != servletContent) {
            //加载上传配置表数据
            SysUploadSet sysUploadSet = sysUploadSetService.getSysUploadSet();
            log.info(sysUploadSet);
            servletContent.setAttribute("sysUploadSet", sysUploadSet);
            servletContent.setAttribute("fileRoot", sysUploadSet.getPublicRoot());
        }

        log.info("====== SYSTEM模块数据初始化完毕 ======");
    }

}
